namespace cnVery.Cms
{
    using cnVery.Utils;
    using System;
    using System.Data;
    using System.Web.UI.WebControls;

    public class Voted : Origin
    {
        protected int count;
        protected Repeater rpvote;
        protected string title;
        protected int vid;

        private void BindVotes()
        {
            this.rpvote.DataSource = votes.GetList(" parentid = " + this.vid.ToString());
            this.rpvote.DataBind();
        }

        private void gettitle()
        {
            string s = Fetch.Get("id");
            int id = RegExp.IsNumeric(s) ? Convert.ToInt32(s) : 0;
            vote model = votes.GetModel(id);
            if (model != null)
            {
                this.title = model.name;
                this.count = model.count;
                this.vid = id;
            }
        }

        private void InitializeComponent()
        {
            base.Load += new EventHandler(this.Page_Load);
            this.rpvote.ItemCreated += new RepeaterItemEventHandler(this.Roll);
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.gettitle();
                if (this.count != 0)
                {
                    this.BindVotes();
                }
            }
        }

        protected void Roll(object o, RepeaterItemEventArgs e)
        {
            DataRowView dataRowViewFromRepeaterItemEventArgs = this.GetDataRowViewFromRepeaterItemEventArgs(e);
            if (dataRowViewFromRepeaterItemEventArgs != null)
            {
                Image image = e.Item.FindControl("img") as Image;
                Label label = e.Item.FindControl("lcount") as Label;
                Label label2 = e.Item.FindControl("lpercent") as Label;
                Label label3 = e.Item.FindControl("lname") as Label;
                int num = 200;
                float num2 = float.Parse(dataRowViewFromRepeaterItemEventArgs["count"].ToString()) / ((float) this.count);
                image.Width = (int) (num2 * num);
                image.ImageUrl = image.ImageUrl.Replace("$skin", "default");
                label.Text = dataRowViewFromRepeaterItemEventArgs["count"].ToString();
                label2.Text = (num2 * 100f).ToString();
                label3.Text = dataRowViewFromRepeaterItemEventArgs["name"].ToString();
            }
        }
    }
}

